package com.cain.calendar.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by Cain on 2016/6/26.
 */
public class CalendarPagerAdapter extends PagerAdapter {

    private Context context;
    private View[] viewArray;

    public CalendarPagerAdapter(Context context, View[] viewArray) {
        this.context = context;
        this.viewArray = viewArray;
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }

    @Override
    public int getCount() {
        if (viewArray == null)
            return 0;
        else
            return viewArray.length;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(viewArray[position]);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        container.addView(viewArray[position]);
        return viewArray[position];
    }
}
